/**
 * 漆水河 脚手架基础公开课
 * 2022/8/13 --- 2022/12/13
 * 有疑问可加QQ群: 809126489，后续会持续输出与大家一起成长
 */
package com.qishuihe.common.application.login;

import com.qishuihe.basedomain.infrastructure.aspect.LogAnnotation;
import com.qishuihe.common.domain.login.LoginService;
import com.qishuihe.baseinterface.basevo.vo.LoginResultVO;
import com.qishuihe.baseinterface.basevo.vo.ResultVO;
import com.qishuihe.outbound.login.ILogin;
import com.qishuihe.outbound.login.UserDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin")
public class LoginControl implements ILogin {

    @Autowired
    private LoginService loginServiceImpl;

    @Override
    @PostMapping(value = "/login",name = "登录1")
    @LogAnnotation
    public LoginResultVO login (@RequestBody UserDTO userDTO) {
        return  loginServiceImpl.login(userDTO);
    }

    @Override
    @PostMapping("/logout")
    @PreAuthorize("hasAuthority('/admin/logout')")
    @LogAnnotation
    public ResultVO<String> logout(@RequestBody UserDTO userDTO) {
        ResultVO<String> resultDto = new ResultVO<>();
        resultDto.setMessage("登出成功");
        loginServiceImpl.logout(userDTO);
        return resultDto;
    }
}
